package t4tools.splittingObjects.splitting;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import t4tools.splittingObjects.config.CompoundPropertyColumnConfig;
import t4tools.splittingObjects.config.RelationConfig;
import t4tools.splittingObjects.filter.RowFilter;
import t4tools.splittingObjects.model.Cell;
import t4tools.splittingObjects.model.CellImpl;
import t4tools.splittingObjects.order.Order;
import t4tools.splittingObjects.util.Relation;

/**
 * Provides information on how to handle column and how rows are produced.
 * 
 * @author yasko
 * 
 */
public class RowConfig {

	private Class<? extends Cell> cellImpl = CellImpl.class;

	private Set<String> repeatedSimpleColumns = new HashSet<String>();

	private Set<String> nonRepeatedSimpleColumns = new HashSet<String>();

	private Set<String> pureArrayColumns = new HashSet<String>();

	private Set<CompoundPropertyColumnConfig> compoundPropertyColumns = new HashSet<CompoundPropertyColumnConfig>();

	private Map<String, RelationConfig> relations = new HashMap<String, RelationConfig>();

	private Set<RowFilter> rowFilters = new HashSet<RowFilter>();

	private Order order;

	public void addOrder(Order order) {
		this.order = order;
	}

	public void addSimpleColumn(String path, boolean repated) {
		if (repated) {
			repeatedSimpleColumns.add(path);
		} else {
			nonRepeatedSimpleColumns.add(path);
		}
	}

	public void addArrayColumn(String path) {
		pureArrayColumns.add(path);
	}

	public void addCompoundPropertyColumn(String key, boolean repeated, String... properties) {
		compoundPropertyColumns.add(new CompoundPropertyColumnConfig(key, repeated, properties));
	}

	public void addRelation(String path, Relation relation, String... relatedPaths) {
		getRelations().put(path, new RelationConfig(path, new HashSet<String>(Arrays.asList(relatedPaths)), relation));
	}

	public void addRowFilter(RowFilter filter) {
		getRowFilters().add(filter);
	}

	public Class<? extends Cell> getCellImpl() {
		return cellImpl;
	}

	public void setCellImpl(Class<? extends Cell> cellImpl) {
		this.cellImpl = cellImpl;
	}

	public Set<String> getRepeatedSimpleColumns() {
		return repeatedSimpleColumns;
	}

	public Set<String> getNonRepeatedSimpleColumns() {
		return nonRepeatedSimpleColumns;
	}

	public Set<String> getPureArrayColumns() {
		return pureArrayColumns;
	}

	public void setPureArrayColumns(Set<String> pureArrayColumn) {
		this.pureArrayColumns = pureArrayColumn;
	}

	public Set<CompoundPropertyColumnConfig> getCompoundPropertyColumns() {
		return compoundPropertyColumns;
	}

	public Map<String, RelationConfig> getRelations() {
		return relations;
	}

	public Set<RowFilter> getRowFilters() {
		return rowFilters;
	}

	public Order getOrder() {
		return order;
	}

}
